﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Combo_U : FormBase1
    {
        public delegate void DoAction(string comboclass);//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        private int? id=null;
        private SVC.client.Combo combo;
        public Combo_U(int ComboID)
        {
            InitializeComponent();
            id = ComboID;
            this.Load+=new EventHandler(Combo_U_Load);
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            valildbefore();
            if (dxValidationProvider1.Validate())
            {
                combo = my.bw.ComboByComboID_Get(id.Value, my.ACID);
                combo.ComboName = te_name.Text;
                combo.DataSize = te_datasize.Text;
                combo.Hours = te_hours.Text;
                combo.Region = te_region.Text;
                combo.inprice = decimal.Parse(sp_inprice.EditValue.ToString());
                combo.outprice = decimal.Parse(sp_outprice.EditValue.ToString());
                combo.LowPrice = decimal.Parse(sp_lowprice.EditValue.ToString());
                combo.TCZ = decimal.Parse(sp_tcz.EditValue.ToString());
                combo.DealerPrice1 = decimal.Parse(sp_lprice1.EditValue.ToString());
                combo.DealerPrice2 = decimal.Parse(sp_lprice2.EditValue.ToString());
                combo.DealerPrice3 = decimal.Parse(sp_lprice3.EditValue.ToString());
                combo.DealerPrice4 = decimal.Parse(sp_lprice4.EditValue.ToString());
                combo.DealerPrice5 = decimal.Parse(sp_lprice5.EditValue.ToString());
                combo.Remarks = moe_remarks.Text;
                string result = my.bw.Combo_Update(combo, my.ACID);
                if(string.IsNullOrWhiteSpace(result))
                {
                    FatherRefresh(combo.ClassCode);
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }

        private void valildbefore()
        {

            te_name.Text = te_name.Text.Trim();

        }



        private void Combo_U_Load(object sender, EventArgs e)
        {
            lue_CarrierID.Properties.DataSource = my.bw.Carrier_Get("", my.ACID);
            lue_Class.Properties.DataSource = my.bw.Combo_Class_Get("", my.ACID);
            lue_GoodCode.Properties.DataSource = my.bw.View_BlankCards_List(my.ACID);
            
            combo = my.bw.ComboByComboID_Get(id.Value, my.ACID);
            lue_Class.EditValue = combo.ClassCode;
            lue_Class.EditValue = combo.ClassCode;
            lue_CarrierID.EditValue = combo.CarrierID;
            lue_GoodCode.EditValue = combo.CardGoodsCode;
            sp_inprice.EditValue = combo.inprice;
            te_Code.Text = combo.ComboCode;
            te_name.Text = combo.ComboName;
            cke_monthflag.Checked = combo.monthFlag;
            te_hours.EditValue = combo.Hours;
            te_datasize.EditValue = combo.DataSize;
            sp_inprice.EditValue = combo.inprice;
            sp_tcz.EditValue = combo.TCZ;
            te_region.EditValue = combo.Region;
            sp_outprice.EditValue = combo.outprice;
            sp_lowprice.EditValue = combo.LowPrice;
            sp_lprice1.EditValue = combo.DealerPrice1;
            sp_lprice2.EditValue = combo.DealerPrice2;
            sp_lprice3.EditValue = combo.DealerPrice3;
            sp_lprice4.EditValue = combo.DealerPrice4;
            sp_lprice5.EditValue = combo.DealerPrice5;
            moe_remarks.EditValue = combo.Remarks;

        }

        private void cke_monthflag_CheckedChanged(object sender, EventArgs e)
        {
            if (cke_monthflag.Checked)
            {
                sp_tcz.Enabled = true;
            }
            else
            {
                sp_tcz.Enabled = false;
                sp_tcz.Text = "";
            }
        }




    }
}